package com.huawei.knowledge.utils;

import com.huawei.knowledge.doc.DocumentController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.*;

/**
 * Created by Administrator on 2018/4/23/023.
 */
public class FileUtils {

    private static Logger myLogger = LogManager.getLogger(FileUtils.class);
    /**
     * 读取文件内容
     *
     * @param filePath 文件路径
     * @return 文件内容
     */
    public static String readFileContent(String filePath) {

        String fileContenr = "";
        InputStreamReader input = null;
        try {
            input = new InputStreamReader(new FileInputStream(filePath), "utf-8");
            int tmp;
            while ((tmp = input.read()) != -1) {
                fileContenr += (char) tmp;
            }
        } catch (FileNotFoundException e) {
            myLogger.error("readFileContent has error : ",e);
        } catch (UnsupportedEncodingException e) {
            myLogger.error("readFileContent has error : ",e);
        } catch (IOException e) {
            myLogger.error("readFileContent has error : ",e);
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    myLogger.error("readFileContent has error : ",e);
                }
            }
        }
        return fileContenr;
    }
}
